package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo13Union {
  def main(args: Array[String]): Unit = {


    val conf = new SparkConf()

    conf.setAppName("union")

    conf.setMaster("local")

    val sc = new SparkContext(conf)


    val rdd1: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5, 6))
    val rdd2: RDD[Int] = sc.parallelize(List(3, 4, 5, 6, 7, 8, 9))

    println(s"rdd1:${rdd1.getNumPartitions}")
    println(s"rdd2:${rdd2.getNumPartitions}")


    /**
      * union :合并两个rd, 不会对数据做去重， 两个rdd的类型要完全一致
      * 在物理层面并没有合并,只是在逻辑层面合并了
      */
    val unionRDD: RDD[Int] = rdd1.union(rdd2)

    println(s"unionRDD:${unionRDD.getNumPartitions}")

    unionRDD.foreach(println)


  }

}
